#!/bin/zsh
# log_utils.zsh - 控制台日志美化工具
# 定义各种日志输出样式和图标

# ========== 颜色和图标定义 ==========

# 颜色定义
RESET="\033[0m"
BOLD="\033[1m"
DIM="\033[2m"
UNDERLINE="\033[4m"
BLINK="\033[5m"
REVERSE="\033[7m"
HIDDEN="\033[8m"

# 前景色
BLACK="\033[30m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
MAGENTA="\033[35m"
CYAN="\033[36m"
WHITE="\033[37m"

# 背景色
BG_BLACK="\033[40m"
BG_RED="\033[41m"
BG_GREEN="\033[42m"
BG_YELLOW="\033[43m"
BG_BLUE="\033[44m"
BG_MAGENTA="\033[45m"
BG_CYAN="\033[46m"
BG_WHITE="\033[47m"

# 环境图标
NODE_ICON="⬢ "
NPM_ICON="📦 "
PNPM_ICON="🔄 "
PYTHON_ICON="🐍 "
CONDA_ICON="🐼 "
JAVA_ICON="☕ "
MAVEN_ICON="🔨 "
GRADLE_ICON="🐘 "
DOCKER_ICON="🐳 "
MONGO_ICON="🍃 "
REDIS_ICON="🔴 "
MYSQL_ICON="🐬 "
DB_ICON="🗄️ "
CONFIG_ICON="⚙️ "
INFO_ICON="ℹ️ "
WARNING_ICON="⚠️ "
ERROR_ICON="❌ "
SUCCESS_ICON="✅ "
LOADING_ICON="🔄 "
ENV_ICON="🌍 "
DIR_ICON="📁 "
HOME_ICON="�� "
PATH_ICON="🔀 "
ANDROID_ICON="🤖 "

# ========== 日志输出函数 ==========

# 基础输出函数
log() {
  echo -e "$@${RESET}"
}

# 标题输出
log_header() {
  echo -e "\n${BOLD}${MAGENTA}=== $@ ===${RESET}\n"
}

# 子标题输出
log_subheader() {
  echo -e "\n${BOLD}${BLUE}--- $@ ---${RESET}\n"
}

# 信息输出
log_info() {
  echo -e "${INFO_ICON} ${CYAN}$@${RESET}"
}

# 成功输出
log_success() {
  echo -e "${SUCCESS_ICON} ${GREEN}$@${RESET}"
}

# 警告输出
log_warning() {
  echo -e "${WARNING_ICON} ${YELLOW}$@${RESET}"
}

# 错误输出
log_error() {
  echo -e "${ERROR_ICON} ${RED}$@${RESET}"
}

# 路径信息输出
log_path() {
  echo -e "${DIR_ICON} ${BLUE}$1:${RESET} ${YELLOW}$2${RESET}"
}

# 版本信息输出
log_version() {
  echo -e "${BOLD}${BLUE}$1:${RESET} ${GREEN}$2${RESET}"
}

# 环境变量输出
log_env() {
  echo -e "${ENV_ICON} ${BOLD}${BLUE}$1:${RESET} ${YELLOW}$2${RESET}"
}

# ========== 特定环境日志函数 ==========

# Node.js 环境日志
log_node() {
  log_version "${NODE_ICON}Node.js" "$1"
}

log_npm() {
  log_version "${NPM_ICON}NPM" "$1"
}

log_pnpm() {
  log_version "${PNPM_ICON}PNPM" "$1"
}

# Python 环境日志
log_python() {
  log_version "${PYTHON_ICON}Python" "$1"
}

log_conda() {
  log_version "${CONDA_ICON}Conda" "$1"
}

# Java 环境日志
log_java() {
  log_version "${JAVA_ICON}Java" "$1"
}

log_maven() {
  log_version "${MAVEN_ICON}Maven" "$1"
}

log_gradle() {
  log_version "${GRADLE_ICON}Gradle" "$1"
}

# Docker 环境日志
log_docker() {
  log_version "${DOCKER_ICON}Docker" "$1"
}

# 数据库环境日志
log_mongo() {
  log_version "${MONGO_ICON}MongoDB" "$1"
}

log_redis() {
  log_version "${REDIS_ICON}Redis" "$1"
}

log_mysql() {
  log_version "${MYSQL_ICON}MySQL" "$1"
}

# Android环境日志
log_android() {
  log_version "${ANDROID_ICON}Android" "$1"
}

# ========== 状态输出函数 ==========
log_running() {
  echo -e "${SUCCESS_ICON} ${GREEN}$1 状态:${RESET} ${BOLD}${GREEN}运行中${RESET}"
}

log_stopped() {
  echo -e "${WARNING_ICON} ${YELLOW}$1 状态:${RESET} ${BOLD}${YELLOW}未运行${RESET}"
}

log_not_installed() {
  echo -e "${ERROR_ICON} ${RED}$1 状态:${RESET} ${BOLD}${RED}未安装${RESET}"
}

# ========== 路径信息函数 ==========
# 用于输出各种环境配置的关键路径
log_node_paths() {
  log_header "Node.js 路径信息"
  log_path "Node.js 可执行文件" "$(which node 2>/dev/null || echo '未安装')"
  log_path "NPM 可执行文件" "$(which npm 2>/dev/null || echo '未安装')"
  log_path "PNPM 可执行文件" "$(which pnpm 2>/dev/null || echo '未安装')"
  log_path "NPM 全局目录" "$NPM_CONFIG_PREFIX"
  log_path "PNPM 全局目录" "$PNPM_HOME"
  log_path "N 版本管理器目录" "$N_PREFIX"
}

log_python_paths() {
  log_header "Python 路径信息"
  log_path "Python 可执行文件" "$(which python 2>/dev/null || echo '未安装')"
  log_path "pip 可执行文件" "$(which pip 2>/dev/null || echo '未安装')"
  log_path "Conda 目录" "$HOME/miniconda3"
  log_path "Conda 环境目录" "$HOME/miniconda3/envs"
  log_path "pipx 应用目录" "$HOME/.local/bin"
}

log_java_paths() {
  log_header "Java 路径信息"
  log_path "JAVA_HOME" "$JAVA_HOME"
  log_path "Java 可执行文件" "$(which java 2>/dev/null || echo '未安装')"
  log_path "Maven 目录" "$M2_HOME"
  log_path "Maven 可执行文件" "$(which mvn 2>/dev/null || echo '未安装')"
  log_path "Gradle 目录" "$GRADLE_HOME"
  log_path "Gradle 可执行文件" "$(which gradle 2>/dev/null || echo '未安装')"
}

log_docker_paths() {
  log_header "Docker 路径信息"
  log_path "Docker 可执行文件" "$(which docker 2>/dev/null || echo '未安装')"
  log_path "Docker Compose 可执行文件" "$(which docker-compose 2>/dev/null || echo '未安装')"
}

log_db_paths() {
  log_header "数据库路径信息"
  log_path "MongoDB 可执行文件" "$(which mongod 2>/dev/null || echo '未安装')"
  log_path "MongoDB 数据目录" "$MONGO_DATA"
  log_path "MongoDB 日志目录" "$MONGO_LOG"
  log_path "Redis 可执行文件" "$(which redis-server 2>/dev/null || echo '未安装')"
  log_path "MySQL 可执行文件" "$(which mysqld 2>/dev/null || echo '未安装')"
}

log_android_paths() {
  log_header "Android SDK 路径信息"
  local android_home="${ANDROID_HOME:-$HOME/Library/Android/sdk}"
  log_path "Android SDK 目录" "$android_home"
  log_path "Android 模拟器" "$android_home/emulator/emulator"
  log_path "Android ADB" "$android_home/platform-tools/adb"
  log_path "Android AVD 目录" "$HOME/.android/avd"
  log_path "Android Gradle 插件缓存" "$HOME/.gradle/caches/modules-2/files-2.1/com.android.tools.build"
}

# 输出所有配置路径信息
log_all_paths() {
  log_header "系统配置路径信息"
  log_node_paths
  log_python_paths
  log_java_paths
  log_docker_paths
  log_db_paths
  log_android_paths
}

# 当这个文件被加载时显示提示信息
log_success "日志工具已加载" 